package com.share.lottery.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.share.lottery.R;

/**
 * @author py
 *选择彩票的父类
 */
public class CpSelectParentAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater inflater;
	private String [] regs;
	private int last_item;
	 
	private int selectedPosition = -1;     
	public CpSelectParentAdapter(Context context,String [] regs){
		this.context = context;
		this.regs = regs;
		
		inflater=LayoutInflater.from(context);
	}


	public int getCount() {

		return regs.length;
	}

	
	public String getItem(int position) {

		return regs[position];
	}


	public long getItemId(int position) {

		return position;
	}


	public View getView(int position, View convertView, ViewGroup parent) {
	
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.mylist_item, null);
			holder = new ViewHolder();
			holder.textView =(TextView)convertView.findViewById(R.id.textview);

			holder.layout=(LinearLayout)convertView.findViewById(R.id.colorlayout);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}
	
		if(selectedPosition == position)   
		{   
			holder.textView.setTextColor(Color.BLUE);   

			//holder.layout.setBackgroundColor(Color.LTGRAY); 
			holder.layout.setBackgroundResource(R.color.gray); 
			
		} else {  
			holder.layout.setBackgroundColor(Color.LTGRAY); 
		//	holder.textView.setTextColor(Color.WHITE);   
			holder.layout.setBackgroundColor(Color.TRANSPARENT);   
		}   


		holder.textView.setText(regs[position]);
		holder.textView.setTextColor(Color.BLACK);

		return convertView;
	}

	public static class ViewHolder{
		public TextView textView;

		public LinearLayout layout;
	}

	public void setSelectedPosition(int position) {   
		Log.i("test", position+"--");
		selectedPosition = position;   
		notifyDataSetChanged();
	}   

}
